//
//  NetWorkViewCtl.m
//  MoreFun
//
//  Created by Pro on 2018/4/30.
//  Copyright © 2018年 Pro. All rights reserved.
//

#import "NetWorkViewCtl.h"

@interface NetWorkViewCtl ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *NetWorkTableView;

@property (nonatomic,strong) NSMutableArray * dataArray;

@end

@implementation NetWorkViewCtl

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"网络请求";
    self.NetWorkTableView.delegate = self;
    self.NetWorkTableView.dataSource = self;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [[UITableViewCell alloc]init];
    cell.textLabel.text = self.dataArray[indexPath.row];
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    return cell;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

-(NSMutableArray *)dataArray{
    if(_dataArray == nil){
        _dataArray = [NSMutableArray arrayWithObjects:@"用户登录",@"图片上传",@"js交互",@"redis数据", nil];
    }
    return _dataArray;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0){
        
        
        NSMutableDictionary *params = [NSMutableDictionary dictionary];
        params[@"mobile_phone"] =  @"18201430259";
        params[@"password"] =  @"123456";
        params[@"platform"] = @"ios";
        params[@"device_id"] = @"driver73eaaeed8fb4402892b624816eb52a85";
        params[@"UUID"] = @"driver73eaaeed8fb4402892b624816eb52a85";
        params[@"type"] = @"2";
        
        [KAppNetRequestWithShowLog(YES) AF_PostNetWorkWithHeaderUrlStr:URL_Login_login Parameter:params completion:^(NSDictionary *dic, NSError *error) {
            if (!error) {
                if ([dic[@"succeed"] intValue] == 1) {
                    
                    NSString * uid   =   GETDEFAULTS(kUserId)
                    NSString  * sid  = GETDEFAULTS(kSecurityId)
                    NSString * image = dic[@"user"][@"avatar"][@"large"];
                    
                    SAVEDEFAULTS(uid, kUserId)
                    SAVEDEFAULTS(sid, kSecurityId)
                    SAVEDEFAULTS(image, kUserAvatar)

                    [self.navigationController pushViewController:[[ImageUpLoadViewCtl alloc] init] animated:YES];
                }
                else  if ([dic[@"succeed"] intValue] == 0) {
                }
            }
        }];

        
        
        
        
        
    }else if (indexPath.row == 1){
        
    }else if (indexPath.row == 2){
        
    }else if (indexPath.row == 3){
        
    }
    
}

@end
